Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

OOP, extended API, example plugin #6

Merged
merged 4 commits into from Jun 28, 2012

Conversation

franz-josef-kaiser
Copy link
Collaborator

  • OOP: I completely moved the plugin to an OOP concept to get rid of all the public functions.
  • Extended API: The API now comes with an array of arguments. This means that I deprecated the $key argument, as it can simply be built from the label, which makes it easier. I then added in the support for a root, so we can use the WP_CONTENT_DIR, WP_PLUGIN_DIR, WPMU_PLUGIN_DIR and the root as containers for additional plugin directories. It now also works (and this was the main reason for this), if you defined an external location for your plugins. I got several local installations, that all together share the local domain plugins.dev for their plugins. This saves me from copy/pasting and updating plugins in several installations and makes development much easier. Moving the arguments to an array will make altering the API arguments much easier later on. I took some time to make shure, that we'll guide people on how to use the new API without breaking existing installations, so everything's backwards compatible. The last thing that was added, is guidance on when to hook the plugin. It's a simply call to _doing_it_wrong() if the current_filter() isn't plugins_loaded. This prevents the usage of the muplugins_loaded hook, but it isn't a loss, as the filter wouldn't help anything, as the plugin runs later.
  • Example Plugin: I added an example plugin to show how stuff works and should be done.
  • Readme: I also added a small changelog to keep people on trac. I got some code somewhere, where we could also extend the plugin info in the list table and move the changelog to a separate file, but that's code for another patch.

Everything's tested in different cases, but you know what: We're all humans and bugs are built in :)


if ( ! class_exists( 'CD_APD_Admin' ) )
{
add_action( 'plugins_loaded', array( 'CD_APD_Admin', 'instance' ) );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooking the main class into plugins_loaded on priority 10. This will allow people better control via hooks. It also makes sure, the new static $instance only runs once.

function register_plugin_directory( $args, $deprecated_dir = '', $deprecated_label = '' )
{
// The call was too late (or too early in case of a MU-Plugin)
if ( 'plugins_loaded' !== current_filter() )
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure we run stuff on the right filter. If not, we're adding a note for the user that she/he should fix stuff.

chrisguitarguy added a commit that referenced this pull request Jun 28, 2012
OOP, extended API, example plugin
@chrisguitarguy chrisguitarguy merged commit 1e71dcb into chrisguitarguy:master Jun 28, 2012
@chrisguitarguy
Copy link
Owner

Merged! Will test tonight.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants